home *** CD-ROM | disk | FTP | other *** search
/ MacFormat España 19 / macformat_19.iso / Shareware / Developers / N Game Library1.1.0E(ppc) / Button Sample(PPC) / Button_Sample(PPC).c < prev   
Encoding:
C/C++ Source or Header  |  1996-06-23  |  3.2 KB  |  125 lines  |  [TEXT/CWIE]

  1. /*============================================================
  2.  
  3.                     N_Number sample program
  4.                     
  5. ============================================================*/
  6.  
  7. #include            "N_Library.h"
  8.  
  9. void             DoEvent            (EventRecord *eventPtr);
  10. void             DoError            (Str255 errorString);
  11. WindowPtr     CreateWindow         (Str255 name);
  12.  
  13.  
  14. #define        WindowSizeX        640
  15. #define        WindowSizeY        480
  16.  
  17. short        NewWindowX;
  18. short        NewWindowY;
  19.  
  20. short        Data_Rsrc = 0;
  21.  
  22. short        Snd_List0[]     = {1000,1001,0};
  23.  
  24. long            counter1         = 2000;                                                //counter
  25. long            counter2         = 2000;
  26. long            counter3         = 2000;
  27.  
  28.  
  29.  
  30. void main(void)
  31. {
  32.     WindowPtr    window;
  33.     short        bt;
  34.  
  35.     ToolboxInit();
  36.     ColorCheck();
  37.     window = CreateWindow("\pN Game Library <Button Sample>");
  38.     N_Window_Set(window,NewWindowX,NewWindowY,WindowSizeX,WindowSizeY);            //set up window
  39.     Open_Resource_File(128,1,&Data_Rsrc);
  40.     N_Pict_Draw(128,0,0,(GrafPtr)Main_Window,false);
  41.     N_Pict_Draw(128,0,0,(GrafPtr)Main_Window,true);                                //draw background
  42.     
  43.     N_Button_Init();                                                            //initialize button set
  44.     N_Font_Init();
  45.     N_Sprite_Set(129,0,14,24,1,11,1,0);                                            //set 11sprites (Sp 0 - 10)for number 
  46.     N_Sprite_Set(130,11,32,32,1,6,1,0);                                            //set 6sprites  (Sp 11 - 16)for button
  47.  
  48.     N_Sound_Load(&Snd_List0[0]);    
  49.  
  50.     N_Font_Set(0,0,0,0,0);                                                        //initialize font set
  51.     Close_Resource_File(&Data_Rsrc);
  52.  
  53.     N_Button_Set(0,0,0,40,410,0,11,12,1000,1001);                                    //set up buttons
  54.     N_Button_Set(0,1,0,80,410,0,13,14,1000,1001);
  55.  
  56.     N_Button_Set(0,2,0,160,410,40,11,12,1000,1001);
  57.     N_Button_Set(0,3,0,200,410,40,13,14,1000,1001);
  58.  
  59.     N_Button_Set(0,4,0,280,410,512,11,12,1000,1001);
  60.     N_Button_Set(0,5,0,320,410,512,13,14,1000,1001);
  61.  
  62.     N_Button_Set(0,6,0,410,410,513,15,16,1000,1001);
  63.     N_Button_Set(0,7,0,470,410,514,15,16,1000,1001);
  64.  
  65.     N_Button_Set(0,8,0,562,410,512,15,16,1000,1001);                                //set Quit button
  66.     N_Button_Put(0);
  67.  
  68.     N_Num_Put(counter1,30,320,5,16,0,0,0);                                        //put counters
  69.     N_Num_Put(counter2,150,320,5,16,0,0,0);
  70.     N_Num_Put(counter3,270,320,5,16,0,0,0);
  71.     
  72.     do
  73.     {
  74.         bt = N_Button_Check(0);
  75.     
  76.         if (bt == 1) counter1++;
  77.         if (bt == 3) counter2++;
  78.         if (bt == 5) counter3++;
  79.  
  80.         if (counter1 == 10000) counter1 = 0;
  81.         if (counter2 == 10000) counter2 = 0;
  82.         if (counter3 == 10000) counter3 = 0;
  83.     
  84.         if (bt == 0) counter1--;
  85.         if (bt == 2) counter2--;
  86.         if (bt == 4) counter3--;
  87.     
  88.         if (counter1 == -1) counter1 = 9999;
  89.         if (counter2 == -1) counter2 = 9999;
  90.         if (counter3 == -1) counter3 = 9999;
  91.     
  92.         if(bt != -1)
  93.         {
  94.             N_Num_Put(counter1,30,320,5,16,0,0,0);                                //updates counters
  95.             N_Num_Put(counter2,150,320,5,16,0,0,0);
  96.             N_Num_Put(counter3,270,320,5,16,0,0,0);
  97.         }
  98.     
  99.     }
  100.     while (bt != 8);                                                                //push quit button?
  101.     N_Sound_Close();                                                            //close sound channels
  102.     ColorRevert();
  103. }
  104.  
  105. WindowPtr CreateWindow (Str255 name)
  106. {
  107.     WindowPtr    window;
  108.     short        centerX,centerY;
  109.     short        windowWidth,windowHeight;
  110.  
  111.  
  112.     window = GetNewWindow (128,nil,(WindowPtr)-1L );
  113.     centerX  = (qd.screenBits.bounds.right -qd.screenBits.bounds.left)/2;
  114.     centerY  = (qd.screenBits.bounds.bottom -qd.screenBits.bounds.top)/2;
  115.     SetWTitle(window,name);
  116.     MoveWindow(window,NewWindowX=centerX-(WindowSizeX/2),NewWindowY=centerY-(WindowSizeY/2),false);
  117.     SizeWindow(window,WindowSizeX,WindowSizeY,TRUE);
  118.  
  119.     ShowWindow(window);
  120.     SetPort((GrafPtr)window );
  121.     return (WindowPtr)window;
  122. }
  123.     
  124.  
  125.